package com.idis.userApp.controller;

import com.idis.entity.person;
import com.idis.entity.Work;
import com.idis.service.ContactService;
import com.idis.service.IntroService;
import com.idis.service.PersonService;
import com.idis.service.WorkService;
import com.sun.org.apache.regexp.internal.RE;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Created by LJH on 2018/1/26.
 */
//@Controller
@RestController
//默认返回json格式
@RequestMapping("/show")
@Api(tags = "展示端接口")
public class ShowController {

    @Autowired
    PersonService personService;
    @Autowired
    WorkService workService;
    @Autowired
    IntroService introService;
    @Autowired
    ContactService contactService;

    @GetMapping("/allperson")
    @ApiOperation("获取所有成员")
    public Map showAllPerson(){
        Map map = new HashMap() ;
        map.put("allPerson", personService.findAll());
        return map;
    }
    @GetMapping("/allteacher")
    @ApiOperation("获取全部指导教师")
    public Map showAllTeacher(){
        Map map = new HashMap() ;
        map.put("allTeacher", personService.findAllTeacher());
        return map;
    }
    //show/allteacher
    @GetMapping("/allstudent")
    @ApiOperation("获取全部学生成员")
    public Map showAllStudent(){
        Map map = new HashMap() ;
        map.put("allStudent", personService.findAllStudent());
        return map;
    }
    @GetMapping("/allwork")
    @ApiOperation("获取全部作品")
    public Map showAllWork(){
        Map map = new HashMap() ;
        map.put("allWork", workService.findAll());
//        model.addAttribute("allWork",workService.findAll());
        return map;
    }

    @GetMapping("/allworkbytype/{type}")
    @ApiOperation("根据类别获取作品")
    public Map showAllWorkByType(@ApiParam("作品类别")@PathVariable Integer type){
        Map map = new HashMap() ;
        map.put("workWithType", workService.findByType(type));
        return map;
    }

    @GetMapping("/findworkbyname/{name}")
    //现用的是精确查询
    @ApiOperation("根据作品名获取作品")
    public Map showWorkLikeName(@ApiParam("作品名")@PathVariable String name){
        Map map = new HashMap() ;
        map.put("workWithName", workService.findLikeName(name));
        return map;
    }
    @GetMapping("/introduction")
    //简介
    @ApiOperation("获取工作室简介")
    public Map showIntroduction(){
        Map map = new HashMap() ;
        map.put("introduction", introService.findAll());
        return map;
    }
    @GetMapping("/contact")
    //简介
    @ApiOperation("获取联系方式")
    public Map showContact(){
        Map map = new HashMap() ;
        map.put("contact", contactService.findAll());
        return map;
    }

}
